package org.geekbang.time.mathbasicthought.lesson3_iteration;

public class Wheat {
    public static void main(String[] args) {
        System.out.println(String.format("国王给了这么多粒：%d", calculateWheat()));


    }

    /**
     * 64棋盘格放满麦子
     *
     * @return 多少粒麦子
     */
    public static long calculateWheat() {
        long sum = 0;
        long numOfWheatInGrid = 0;

        numOfWheatInGrid = 1;
        sum += numOfWheatInGrid;

        for (int i = 2; i <= 63; i++) {
            numOfWheatInGrid *= 2;
            sum += numOfWheatInGrid;
        }

        return sum;
    }
}
